$(function () {
    var page = 1
    var pageSize = 5
    var currentPage = 1

    function render() {
        $.ajax({
            url: '/category/queryTopCategoryPaging',
            dataType: 'json',
            data: {
                page: currentPage,
                pageSize: pageSize
            },
            success: function (info) {
                $('tbody').html(template('oneTemp', info))
                var total = Math.ceil(info.total/info.size)
                setPage(total)
            }
        })
    }
    render()

    function setPage(total) {
        $("#pagintor").bootstrapPaginator({
            bootstrapMajorVersion: 3,//默认是2，如果是bootstrap3版本，这个参数必填
            currentPage: currentPage,//当前页
            totalPages: total || 5,//总页数
            size: "small",//设置控件的大小，mini, small, normal,large
            onPageClicked: function (event, originalEvent, type, page) {
                //为按钮绑定点击事件 page:当前点击的按钮值
                console.log(page)
                currentPage = page
                render()
            }
        });
    }


    /* 添加分类 */
    $('.cate_add').click(function(){
        var categoryName = $('#form').serialize()
        $.ajax({
            url:'/category/addTopCategory',
            type:'POST',
            dataType: 'json',
            data: categoryName,
            success: function(info) {
                console.log(info)
                render()
                $('.modal-add').modal('hide')
            }
        })
    })
})

